/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author sunwei
 */
public class PasswordValidator implements Validator{

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
              
        String password = (String) component.getAttributes().get("password");

      
        String confirm = (String) value;

        
        if (!password.equals(confirm)) {
            throw new ValidatorException(new FacesMessage("Passwords are not equal."));
        }

        if(password.length()<6||password.length()>15){
            throw new ValidatorException(new FacesMessage("Password length should be between 6 and 15 characters."));
        }
    }
        
    
    
}
